<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		
		<span id="span1" style="color: red;"></span>
		<br />
		<span id="span2">现在是：2021年6月10日10:58:58</span>
		
		<br />
		<button onclick="test1();">获取当前时间</button>
		<br />
		<button onclick="test2();">数学函数</button>
		<br />
		<button onclick="test3();">随机更改时间的颜色</button>
		<br />
		
		<button onclick="test4()">3秒之后谈个框</button>
		<br />
		<button onclick="test5()">每隔3秒谈个框</button>
		<br />
		
		
		
		<script type="text/javascript">
			function test1(){
				var date = new Date();
				//获取年 
				var year  = date.getFullYear();
				//获取月
				var mon = date.getMonth()+1;
				//日
				var day = date.getDate();
				//星期
				var week = date.getDay();
				
				//时
				var hour = date.getHours();
				//分
				var fen = date.getMinutes();
				//秒
				var miao = date.getSeconds();
				
				//输出在页面中
				var span = document.getElementById("span1");
				span.innerHTML = "今天是："+year+"年"+mon+"月"+day+"日"+hour+":"+fen+":"+miao+",星期"+week;
			}
			
			//数学函数
			function test2 (){
				//上舍入
				alert(Math.ceil(2.3));		//3
				//下舍入
				alert(Math.floor(2.3));		//2
				//四舍五入
				alert(Math.round(2.3));		//2
				//1-10之间的随机数
				alert(Math.ceil(Math.random()*10));
			}
			
			//随机更改颜色
			function test3(){
				//声明一个颜色的数组
				var colors = ["red","blue","orange","yellow","pink","purple","green"];
				//随机数
				var ran = Math.random()*6;
				//向下舍入
				var index = Math.floor(ran);
				//改变颜色
				var span2 = document.getElementById("span2");
				//设置css属性
				span2.style.color = colors[index];
			}
			
			//3秒之后谈个框
			function test4(){
				setTimeout("alert('谈出来啦');",3000);
			}
			
			//每隔1秒谈个框
			function test5(){
				//setInterval("alert('弹出来了');",1000);
				//时钟特效
				setInterval("test1()",1000);
			}
			
		</script>
	</body>
</html>
